package com.chinasoft.news.mapper;

import com.chinasoft.news.pojo.Articles;
import com.chinasoft.news.pojo.ArticlesAndCate;
import com.chinasoft.news.pojo.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ArticlesMapper {

    @Insert("insert into ev_articles(title,content,cover_img,pub_date,state,is_delete,cate_id,author_id) values(#{title},#{content},#{cover_img},#{pub_date},#{state},#{is_delete},#{cate_id},#{author_id})")
    int insertArticle(Articles articles);

    @Select("select a.*, c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0")
    List<ArticlesAndCate> selectPage();


    @Select("select a.*, c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0")
    List<ArticlesAndCate> selectAll();

    @Select("select a.*, c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.cate_id=#{cate_id} and a.state=#{state}")
    List<ArticlesAndCate> selectPageSelect(@Param("cate_id") Integer cate_id,@Param("state") String state);

    @Select("select a.*,c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.cate_id=#{cate_id} and a.state=#{state}")
    List<ArticlesAndCate> selectBySelect(@Param("cate_id") Integer cate_id,@Param("state") String state);

    @Select("select a.*, c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.cate_id=#{cate_id} and a.state=#{state}")
    List<ArticlesAndCate> selectPageCateId( Integer cate_id);

    @Select("select a.*,c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.cate_id=#{cate_id}")
    List<ArticlesAndCate> selectByCateId(Integer cate_id);

    @Select("select a.*, c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.cate_id=#{cate_id} and a.state=#{state}")
    List<ArticlesAndCate> selectPageState(String state);


    @Select("select a.*,c.name from ev_articles a left join ev_article_cate c on a.cate_id = c.id  where a.is_delete=0 and a.state=#{state}")
    List<ArticlesAndCate> selectByState( String state);

    @Update("update ev_articles set is_delete=1 where id=#{id}")
    int deleteArticles(Integer id);

    @Select("select * from ev_articles where id=#{id}")
    Articles selectById(Integer id);

    @Update("update ev_articles set title=#{title} ,state=#{state} where id=#{id}")
    int updateById(@Param("title") String title ,@Param("state") String state,@Param("id") Integer id);

    @Select("select * from ev_articles where title=#{title}")
    List<Articles> selectByTitle(String title);




}
